
const app = getApp()

Page({
  data: {
    activeggIndex: 0,
    ggList: [],
    areas:[],
    area:"城市",
    hys:[],
    hy:'行业',
    jns:[],
    jn:'技能',
    nxs:[],
    nx:'年限',
    page: 1,
    flag:0,
    none:'',
    recruit_list:[],
    keyword:""
  },

  onLoad: function () {
    var that = this;
    that.getIndexTop();
  },

  onShow:function(){
    var that=this;
    setTimeout(() => {
      that.getRecruitList();
    }, 300);
  },

  getIndexTop: function(){
    var that = this;
    wx.request({
      url: app.globalData.domain + 'Index/GetIndexTop',
      method: "POST",
      data: {},
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        that.setData({
          ggList:res.data.adv_list,
          areas: res.data.areas,
          hys: res.data.hys,
          jns: res.data.jns,
          nxs: res.data.nxs
        })
      }
    })
  },

  keyword:function(e){
    console.log(e.detail.value);
    this.setData({
      keyword: e.detail.value
    })
  },

  search:function(e){
    var that = this;
    that.setData({
      flag:0,
      none:'',
      house_list:[],
      page:1
    })
    that.getRecruitList();
  },

  resetSearch:function(){
    var that = this;
    that.setData({
      area:"城市",
      hy:'行业',
      jn:'技能',
      nx:'年限',
      page: 1,
      flag:0,
      none:'',
      recruit_list:[],
      keyword:""
    })
    that.getRecruitList();
  },

  getRecruitList:function(){
    var that = this;
    wx.showToast({
      title: '加载中...',
      icon: 'loading',
      duration: 300,
    })
    wx.request({
      url: app.globalData.domain + 'Index/GetRecruitList',
      method: "POST",
      data: {
        area : that.data.area,
        hy : that.data.hy,
        jn : that.data.jn,
        nx : that.data.nx,
        keyword : that.data.keyword,
        page: that.data.page
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res.data)
        if(res.data.code == 200){
          if(res.data.recruit_list.length>0){
            that.setData({
              recruit_list: that.data.recruit_list.concat(res.data.recruit_list),
              page: parseInt(that.data.page) + 1
            })
          }else{
            that.setData({
              none: '暂无更多招聘信息',
              flag:1
            });
          }
          if (that.data.recruit_list.length == 0) {
            that.setData({
              none: '暂无招聘信息'
            });
          }
        }
        }
        
    })
  },

  areaChange: function(e) {
    var that = this;
    if(e.detail.value==0){
      that.setData({
        area: '城市'
      })
    }else{
      that.setData({
        area: that.data.areas[e.detail.value],
      })
    }
    that.setData({
      page: 1,
      flag:0,
      none:'',
      recruit_list:[]
    })
    that.getRecruitList();
  },

  hyChange: function(e) {
    var that = this;
    if(e.detail.value==0){
      that.setData({
        hy: '行业'
      })
    }else{
      that.setData({
        hy: that.data.hys[e.detail.value],
      })
    }
    that.setData({
      page: 1,
      flag:0,
      none:'',
      recruit_list:[]
    })
    that.getRecruitList();
  },

  jnChange: function(e) {
    var that = this;
    if(e.detail.value==0){
      that.setData({
        jn: '技能'
      })
    }else{
      that.setData({
        jn: that.data.jns[e.detail.value],
      })
    }
    that.setData({
      page: 1,
      flag:0,
      none:'',
      recruit_list:[]
    })
    that.getRecruitList();
  },

  nxChange: function(e) {
    var that = this;
    if(e.detail.value==0){
      that.setData({
        nx: '年限'
      })
    }else{
      that.setData({
        nx: that.data.nxs[e.detail.value],
      })
    }
    that.setData({
      page: 1,
      flag:0,
      none:'',
      recruit_list:[]
    })
    that.getRecruitList();
  },

  changeggImg(e) {
    let that = this
    that.activeggIndex = e.detail.current
    this.setData({
      activeggIndex: e.detail.current
    })
  },

  go_recruit: function (e) {
    if (e.currentTarget.dataset.id != 0) {
      wx.navigateTo({
        url: '/pages/recruit/recruit?id=' + e.currentTarget.dataset.id
      })
    }
  },

  share_question: function (e) {
    var that = this;
    return {
      title: e.currentTarget.dataset.id,
      path: '/pages/question/question?id=' + e.currentTarget.dataset.id
    }
  },

  onReachBottom: function () {
    var that = this;
    if(that.data.flag==0){
      that.getRecruitList();
    }
  },

  onShareAppMessage: function (e) {
    var that = this;
    return {
      title: '云数智学堂',
      path: '/pages/index/index'
    }
  }
  
})
